package com.tengfei.blogsystem.controller.admin;

import com.tengfei.blogsystem.pojo.Category;
import com.tengfei.blogsystem.response.ResponseResult;
import com.tengfei.blogsystem.service.ICategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * @version v1.0
 * @author} feige
 * @date 2021-10-15-15:55
 * @description
 */

/**
 * 分类api
 */
@PreAuthorize("@permission.admin()")    //需要管理员权限
@RestController
@RequestMapping("/admin/category")
public class CategoryAdminApi {

    @Autowired
    ICategoryService categoryService;

    /**
     * 添加分类
     *
     * @param category
     * @return
     */
    @PostMapping
    public ResponseResult addCategory(@RequestBody Category category) {
        return categoryService.addCategory(category);
    }

    /**
     * 删除分类
     *
     * @param categoryId
     * @return
     */
    @DeleteMapping("/{categoryId}")
    public ResponseResult deleteCategory(@PathVariable("categoryId") String categoryId) {
        return categoryService.deleteCategory(categoryId);
    }

    /**
     * 修改分类
     *
     * @param categoryId
     * @param category
     * @return
     */
    @PutMapping("/{categoryId}")
    public ResponseResult updateCategory(@PathVariable("categoryId") String categoryId, @RequestBody Category category) {
        return categoryService.updateCategory(categoryId, category);
    }

    /**
     * 查询分类
     *
     * @param categoryId
     * @return
     */
    @GetMapping("/{categoryId}")
    public ResponseResult getCategory(@PathVariable("categoryId") String categoryId) {
        return categoryService.getCategory(categoryId);
    }

    /**
     * 查询所有分类
     *
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/list/{page}/{size}")
    public ResponseResult listCategory(@PathVariable("page") int page, @PathVariable("size") int size) {
        return categoryService.listCategory(page, size);
    }
}
